﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using S4Store.Domain.FinancialKpi;
using LX.Web.Excel;

namespace S4Store.Domain.FinancialReport
{
    public class FinancialCommonReport : ExportObject
    {

        [Export("合计标题")]
        public virtual string HjTitle
        {
            get
            {
                return "合计";
            }
        }

        public FinancialCommonReport()
        {
            FinancialCarBrandMonthConfigs = new List<FinancialCarBrandMonthConfig>();
            FinancialDayDatas = new List<FinancialDayData>();
            CarTypeReport = new AfterSaleReport.CarTypeReport();
        }

        public int Year { get; set; }
        public int Month { get; set; }
        public int Day { get; set; }

        public FinancialMonthConfig FinancialMonthConfig { get; set; }
        public List<FinancialCarBrandMonthConfig> FinancialCarBrandMonthConfigs { get; set; }
        public List<FinancialDayData> FinancialDayDatas { get; set; }
        public AfterSaleReport.CarTypeReport CarTypeReport { get; set; }

        /// <summary>
        /// 服务吸收率贡献度
        /// </summary>
        [Export("服务吸收率贡献度", Format = "{0}%")]
        public virtual decimal FWXSLGXD
        {
            get
            {
                return 100;
            }
        }
        /// <summary>
        /// 本月4S店运营成本
        /// </summary>
        [Export("本月4S店运营成本")]
        public virtual decimal YYCB
        {
            get
            {
                return FinancialMonthConfig.YYCB;
            }
        }

        /// <summary>
        /// 销售额
        /// </summary>
        [Export("销售额")]
        public virtual decimal XSE {
            get
            {
                return FinancialDayDatas.Sum(t => t.XSZE);
            }
        }

        /// <summary>
        /// 月初库存成本
        /// </summary>
        [Export("月初库存成本")]
        public virtual decimal YCKCCB
        {
            get
            {
                return FinancialCarBrandMonthConfigs.Sum(t => t.YCKCCB);
            }
        }

        /// <summary>
        /// 月末库存成本
        /// </summary>
        [Export("月末库存成本")]
        public virtual decimal YMKCCB
        {
            get
            {
                return FinancialCarBrandMonthConfigs.Sum(t => t.YMKCCB);
            }
        }


        /// <summary>
        /// 库存平均成本
        /// </summary>
        [Export("月库存平均成本")]
        public virtual decimal KCPJCB
        {
            get
            {
                return FinancialCarBrandMonthConfigs.AverageOrDefault(t => (t.YCKCCB + t.YMKCCB) / 2);
            }
        }

        /// <summary>
        /// 车辆销售成本
        /// </summary>
        [Export("本月车辆销售成本")]
        public virtual decimal CLXSCB
        {
            get
            {
                return FinancialCarBrandMonthConfigs.Sum(t =>t.CLXSCB);
            }
        }

        /// <summary>
        /// 库存资金周转天
        /// </summary>
        [Export("库存资金周转天")]
        public virtual decimal KCZJZZT
        {
            get
            {
                if (CLXSCB == 0 || KCPJCB==0)
                {
                    return 0 ;
                }
                return 365 / ((CLXSCB * 12) / KCPJCB);
            }
        }
        /// <summary>
        /// 目标周转天数
        /// </summary>
        [Export("目标周转天数")]
        public virtual decimal MBZZTS
        {
            get
            {
                return FinancialMonthConfig.MBZZTS;
            }
        }

        /// <summary>
        /// 库存资金周转天差异
        /// </summary>
        [Export("库存资金周转天差异")]
        public decimal KCZJZZTDiff
        {
            get
            {
                return KCZJZZT-FinancialMonthConfig.MBZZTS ;
            }
        }

        /// <summary>
        /// 售后总产值
        /// </summary>
        [Export("本月售后总产值")]
        public virtual decimal SHZCZ
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.SHCZ);
                //return FinancialCarBrandMonthConfigs.Sum(t => t.SHZCZ);
            }
        }

        /// <summary>
        /// 售后总产值
        /// </summary>
        public virtual decimal SHZCZDiff
        {
            get
            {
                return SHZCZ-FinancialMonthConfig.MBSHZCZ;
            }
        }

        /// <summary>
        /// 服务吸收率目标
        /// </summary>
        [Export("服务吸收率目标", Format = "{0}%")]
        public virtual decimal FWXSLVTarget
        {
            get
            {
                return FinancialMonthConfig.GSFWXSLVMB;
            }
        }

        /// <summary>
        /// 服务吸收率
        /// </summary>
        [Export("本月服务吸收率", Format = "{0}%")]
        public virtual decimal FWXSLV
        {
            get
            {
                if (FinancialMonthConfig.YYCB == 0) return 0;
                return BYSHML * 100 / FinancialMonthConfig.YYCB;
            }
        }

        /// <summary>
        /// 本    月    售    后    毛    利
        /// </summary>
        public virtual decimal BYSHML
        {
            get
            {
                return SHZCZ;
            }
        }

        /// <summary>
        /// 服务吸收率差异
        /// </summary>
        [Export("服务吸收率差异", Format = "{0}%")]
        public virtual decimal FWXSLVDiff
        {
            get
            {
                return FWXSLV - FWXSLVTarget;
            }
        }

        /// <summary>
        /// 商品车销售额
        /// </summary>
        [Export("商品车销售额")]
        public decimal SPCXSE
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.SPCXSE);
            }
        }
        /// <summary>
        /// 商品车占比
        /// </summary>
        [Export("商品车营业额占比", Format = "{0}%")]
        public decimal SPCZB
        {
            get
            {
                if (XSE == 0) return 0;
                return SPCXSE * 100 / XSE;
            }
        }

        /// <summary>
        /// 装潢营业额
        /// </summary>
        [Export("装潢营业额")]
        public decimal ZHXSE
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.ZHXSE);
            }
        }
        /// <summary>
        /// 装潢占比
        /// </summary>
        [Export("装潢营业额占比", Format = "{0}%")]
        public decimal ZHZB
        {
            get
            {
                if (XSE == 0) return 0;
                return ZHXSE * 100 / XSE;
            }
        }

        /// <summary>
        /// 保险销售额
        /// </summary>
        [Export("保险销售额")]
        public decimal BXXSE
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.BXXSE);
            }
        }
        /// <summary>
        /// 保险占比
        /// </summary>
        [Export("保险营业额占比", Format = "{0}%")]
        public decimal BXZB
        {
            get
            {
                if (XSE == 0) return 0;
                return BXXSE * 100 / XSE;
            }
        }

        /// <summary>
        /// 贷款销售额
        /// </summary>
        [Export("贷款销售额")]
        public decimal DKFWE
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.DKFWE);
            }
        }
        /// <summary>
        /// 贷款占比
        /// </summary>
        [Export("贷款服务费占比", Format = "{0}%")]
        public decimal DKZB
        {
            get
            {
                if (XSE == 0) return 0;
                return DKFWE * 100 / XSE;
            }
        }
        /// <summary>
        /// 二手车销售额
        /// </summary>
        [Export("二手车销售额")]
        public decimal ESCXSE
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.ESCXSE);
            }
        }
        /// <summary>
        /// 二手车毛利
        /// </summary>
        [Export("二手车毛利")]
        public decimal ESCML
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.ESCML);
            }
        }
        /// <summary>
        /// 二手车毛利占比
        /// </summary>
        [Export("二手车毛利占比", Format = "{0}%")]
        public decimal ESCMLZB
        {
            get
            {
                if (XSE == 0) return 0;
                return ESCML * 100 / XSE;
            }
        }

        /// <summary>
        /// 延保营业额
        /// </summary>
        [Export("延保销售额")]
        public decimal YBYYE
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.YBXSE);
            }
        }
        /// <summary>
        /// 延保占比
        /// </summary>
        [Export("延保营业额占比", Format = "{0}%")]
        public decimal YBZB
        {
            get
            {
                if (XSE == 0) return 0;
                return YBYYE * 100 / XSE;
            }
        }

        /// <summary>
        /// 事故车总产值
        /// </summary>
        [Export("事故车总产值")]
        public decimal SGCCZ
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.SJCCZ);
            }
        }
        /// <summary>
        /// 事故车占比
        /// </summary>
        [Export("事故车产值占比", Format = "{0}%")]
        public decimal SGCCZZB
        {
            get
            {
                if (SHZCZ == 0) return 0;
                return SGCCZ * 100 / SHZCZ;
            }
        }


        /// <summary>
        /// 保养产值
        /// </summary>
        [Export("保养产值")]
        public decimal BYCZ
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.BYCZ);
            }
        }
        /// <summary>
        /// 保养占比
        /// </summary>
        [Export("保养产值占比", Format = "{0}%")]
        public decimal BYCZZB
        {
            get
            {
                if (SHZCZ == 0) return 0;
                return BYCZ * 100 / SHZCZ;
            }
        }


        /// <summary>
        /// 维修产值
        /// </summary>
        [Export("维修产值")]
        public decimal WXCZ
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.WXCZ);
            }
        }
        /// <summary>
        /// 维修占比
        /// </summary>
        [Export("维修产值占比", Format = "{0}%")]
        public decimal WXCZZB
        {
            get
            {
                if (SHZCZ == 0) return 0;
                return WXCZ * 100 / SHZCZ;
            }
        }

        /// <summary>
        /// 备件产值
        /// </summary>
        [Export("备件产值")]
        public decimal BJCZ
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.BJCZ);
            }
        }
        /// <summary>
        /// 备件占比
        /// </summary>
        [Export("备件销售产值占比", Format = "{0}%")]
        public decimal BJCZZB
        {
            get
            {
                if (SHZCZ == 0) return 0;
                return BJCZ * 100 / SHZCZ;
            }
        }


        /// <summary>
        /// 装潢产值
        /// </summary>
        [Export("装潢产值")]
        public decimal ZHCZ
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.ZHCZ);
            }
        }
        /// <summary>
        /// 装潢占比
        /// </summary>
        [Export("装潢销售产值占比", Format = "{0}%")]
        public decimal ZHCZZB
        {
            get
            {
                if (SHZCZ == 0) return 0;
                return ZHCZ * 100 / SHZCZ;
            }
        }

        /// <summary>
        /// 养护产品产值
        /// </summary>
        [Export("养护产品产值")]
        public decimal YHCPCZ
        {
            get
            {
                return FinancialDayDatas.Sum(t => t.YHCPCZ);
            }
        }
        /// <summary>
        /// 养护产品占比
        /// </summary>
        [Export("养护产品产值占比", Format = "{0}%")]
        public decimal YHCPCZZB
        {
            get
            {
                if (SHZCZ == 0) return 0;
                return YHCPCZ * 100 / SHZCZ;
            }
        }
    }
}
